package dolf.window;

import java.awt.*;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
//import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

//import dolf.game.Level;
import dolf.game.Player;
import dolf.game.Game;


public class ScoreDisplay extends JScrollPane {
	private static final long serialVersionUID = 1L;
	
	private static ScoreDisplay instance = new ScoreDisplay();
	
	private ScoreDisplay() {
		getVerticalScrollBar().setUnitIncrement(5);
		setPreferredSize(new java.awt.Dimension(695,45));
		setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		setViewportBorder(new EmptyBorder(0,0,0,0));
		setBorder(new EmptyBorder(0,0,0,5));
	}
	
	public static ScoreDisplay getInstance() {
		return instance;
	}
	
	public void draw() {
		//removeAll();
		final JPanel pane = new JPanel();
		//pane.setLayout(new GridLayout(0,5));
		pane.setLayout(new FlowLayout(FlowLayout.LEADING,0,0));
		pane.setPreferredSize(new Dimension(680, 80));
		for (int i = 0; i < Game.getInstance().getPlayerList().size(); i++) {
			JPanel pPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
			Player pl = Game.getInstance().getPlayerList().get(i);
			JLabel nameLabel =  new JLabel("<html><font size=4>"+pl.getName()+"</font></html>");
			nameLabel.setForeground(pl.getColor());
			pPane.add(nameLabel);
			nameLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
			
			
			int[][] scores = pl.getScoreList();
			for (int j = 0; j < scores.length; j++) {
				String space = "";
				if (j < scores.length-1) space = "|";
				pPane.add(new JLabel("<html><p align=right><font size=3>"+String.valueOf(scores[j][0])+space+"<br>"+String.valueOf(scores[j][1])+space+"</font></p></html>"));
			}
			JLabel space = new JLabel();
			if (i < Game.getInstance().getPlayerList().size()) space.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
			pPane.add(space);
			pane.add(pPane);
		}
		setViewportView(pane);
		
		MainWindow.getInstance().actualize();
	}
}
